<template>
  <div id="djradio">
    <ul class="catelist">
      <li
        v-for="(cate, index) in categories"
        :key="cate.id"
        @click="toRadiolist(cate.id, index)"
      >
        <div class="category" :class="{ redBorder: activeIndex == index }">
          <div
            class="black"
            :class="{ white: activeIndex == index }"
            :style="{ backgroundImage: `url(${cate.picWebUrl})` }"
          ></div>
          <em style="font-size: 12px">{{ cate.name }}</em>
        </div>
      </li>
    </ul>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "Djradio",
  data() {
    return {
      categories: [],
      activeIndex: -1,
    };
  },
  mounted() {
    this.$API.djCatelist().then((res) => {
      if (res.data.code === 200) {
        this.categories = res.data.categories;
      }
    });
  },
  methods: {
    toRadiolist(cateId, index) {
      this.activeIndex = index;
      this.$router.push({
        name: "radiolist",
        query: { cateId, order: "new" },
      });
    },
  },
};
</script>

<style scoped lang='less'>
#djradio {
  width: 1020px;
  background-color: #ffffff;
  color: #333333;
  margin: 0 auto;
  padding: 40px;
  border: 1px solid #cdcdcd;

  .catelist {
    display: flex;
    flex-flow: row wrap;
    justify-content: space-between;

    li {
      height: 70px;
      width: 70px;
      display: flex;
      justify-content: center;
      margin: 0 30px 20px 0;

      .category {
        width: 70px;
        display: flex;
        flex-flow: column;
        align-items: center;
        border-radius: 5px;
      }

      .redBorder {
        border: #c20c0c 2px solid;
      }

      .category:hover {
        background-color: #eaeaea;
      }

      .black {
        width: 48px;
        height: 48px;
        background-position: 0 0;
      }

      .white {
        width: 48px;
        height: 48px;
        background-position: -48px 0 !important;
      }
    }
  }
}
</style>